home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14043 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. From: gsobrian@msn.com (Glenn Sobrian)
  2. Subject: RE: Simple Question for the GURUs....
  3. Date: 28 Mar 96 22:45:09 -0800
  4. References: <1996Mar21.093000.3545@mwk.com>
  5. Message-ID: <00001a81+0000b05c@msn.com>
  6. Path: news.msn.com!msn.com
  7. Newsgroups: comp.lang.c++
  8. Organization: The Microsoft Network (msn.com)
  9.  
  10. I don't think you can return a pointer from within your program to 
  11. any memory allocated with malloc.  The problem here is two-fold.
  12.  
  13. 1)  NT will clean up the Virtual Memory after it has finished running 
  14. your program in its own address space.  Thus your pointer is crap by 
  15. the time it is returned.
  16.  
  17. 2)  NT (and any Win32 based environment such as Windows 95) uses 
  18. demand page virtual memory.  These memory addresses are "VIRTUAL", 
  19. that means that the address 0FFFFFFA in process A is not the same as 
  20. address 0FFFFFFA in process B.  They are both mapped onto different 
  21. protected virtual memory space which is owned by the process.  You 
  22. 'may' have gotten away with that little trick in DOS because it 
  23. doesn't do shit for memory management.
  24.  
  25. I'm not sure how to do what you want to do.  Try looking at the API - 
  26. such as doing the memory allocation through Win32 GlobalAlloc.  The 
  27. stuff you are doing here is one of the reasons why COM/OLE has been 
  28. developed so you might take a look at using the MFC COleVariant class 
  29. to pass the information to your program somehow.
  30.  
  31. Hope that helps.
  32. ---
  33. Glenn Sobrian
  34. gsobrian@msn.com
  35.